package com.globallogic.capacitaciones.hibernate.mo;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cubika.devsupport.motherobject.DatabaseProviderMotherObjectImpl;
import com.cubika.devsupport.motherobject.TestObject;
import com.globallogic.capacitaciones.hibernate.domain.Comment;

@Component
public class CommentMO extends DatabaseProviderMotherObjectImpl<Comment>{

	@Autowired
	private UserMO userMo;
	
	@Autowired
	private ItemMO itemMo;
	
	public CommentMO() {
		super(Comment.class);
	}

	@Override
	public Comment getDefault() {
		return getFirstComentPerez();
	}

	@TestObject
	public Comment getThirdCommentPerez(){
		String name = "sampleItem";
		if(!instanceExists(name)){
			GregorianCalendar theDayBeforeYesterday = new GregorianCalendar();
			theDayBeforeYesterday.roll(Calendar.DAY_OF_MONTH, -1);
			Comment comment = new Comment("Comentario sobre el Item de prueba", theDayBeforeYesterday.getTime(), itemMo.getDefault(), userMo.getDefault());
			addInstance(name, comment);
		}
		return getInstance(name);
	}
	
	@TestObject
	public Comment getFirstComentPerez(){
		String name = "sampleItem";
		if(!instanceExists(name)){
			Date now = new Date();
			Comment comment = new Comment("Primer Comentario sobre el Item de prueba de Juan Perez", now, itemMo.getDefault(), userMo.getDefault());
			addInstance(name, comment);
		}
		return getInstance(name);
	}
	
	@TestObject
	public Comment getSecondComentPerez(){
		String name = "sampleItem";
		if(!instanceExists(name)){
			GregorianCalendar yesterday = new GregorianCalendar();
			yesterday.roll(Calendar.DAY_OF_MONTH, -1);
			Comment comment = new Comment("Segundo Comentario sobre el Item de prueba de Juan Perez", yesterday.getTime(), itemMo.getDefault(), userMo.getDefault());
			addInstance(name, comment);
		}
		return getInstance(name);
	}
	
	
	@TestObject
	public Comment getFirstComentParada(){
		String name = "sampleItem";
		if(!instanceExists(name)){
			Date now = new Date();
			Comment comment = new Comment("Segundo Comentario sobre el Item de prueba de Juan Perez", now, itemMo.getDefault(), userMo.getUserParada());
			addInstance(name, comment);
		}
		return getInstance(name);
	}
}
